<?php
namespace app\model;

class CourseOutline extends BaseModel
{
    protected $name = 'course_outlines';

    // 自动时间戳
    protected $autoWriteTimestamp = true;

    // 类型转换
    protected $type = [
        'teaching_plan_ids' => 'json',
        'recommended_course_ids' => 'json',
        'created_at' => 'integer',
        'updated_at' => 'integer',
        'delete_time' => 'integer'
    ];

    // 课程状态常量
    const STATUS_DRAFT = 0;     // 草稿
    const STATUS_PUBLISHED = 1; // 已发布
    const STATUS_OFFLINE = 2;   // 已下架

    /**
     * 关联用户
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * 获取关联的教案列表
     */
    public function getTeachingPlans()
    {
        return TeachingPlan::whereIn('id', $this->teaching_plan_ids)->select();
    }

    /**
     * 获取推荐课程列表
     */
    public function getRecommendedCourses()
    {
        return self::whereIn('id', $this->recommended_course_ids)->select();
    }
} 